package main

import (
	"fmt"
    "os"
    "../json2csv"
    "encoding/csv"
)

func main() {
	// below is missing the initial opening brace
	b := []byte(
`{
"1":
    {
    "1.1":
        {
        "1.1.1":"p1",
        "1.1.2":"p2",
        "1.1.3":"p3"
        },
    "1.2":
        {
        "1.2.1":"p4",
        "1.2.2":"p5",
        "1.2.3":"p6"
        },
    "1.3":
        {
        "1.3.1":"p7",
        "1.3.2":"p8",
        "1.3.3":["p9","p10","p11"]
        }
    },
"2":
    {
    "2.1":
        {
        "2.1.1":"p12",
        "2.1.2":"p13",
        "2.1.3":"p14"
        },
    "2.2":
        {
        "2.2.1":"p15",
        "2.2.2":"p16",
        "2.2.3":"p17"
        },
    "2.3":
        {
        "2.3.1":"p18",
        "2.3.2":"p19",
        "2.3.3":["p20","p21","p22"]
        }
    }
}`) 
	s := json2csv.New(b,50,5)
    if err := s.Parse(); err != nil {
        fmt.Print("Found invalid JSON data:%v\n",err)
        return
    } 

    csv_writer := csv.NewWriter(os.Stdout)
    if err := csv_writer.WriteAll(s.Records); err != nil {
        fmt.Print("WriteAll() err:"+err.Error())
    }
}
